#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> s;
		if (s.size() == 1 && s[0] == '^') {
			cout << 1 << endl;
			continue;
		}
		int ans = 0;
		char pre = s[0];
		if (pre == '_')ans++;
		for (int i = 1; i < s.size(); i++) {
			if (s[i] == '_') {
				if (pre == '_')ans++;
			}
			pre = s[i];
		}
		if (pre == '_')ans++;
		cout << ans << endl;
	}
	return 0;
}